#ifndef OSGGRID_H
#define OSGGRID_H

#include <osg/ref_ptr>
#include <osg/MatrixTransform>

class OSGRect
{
public:
    OSGRect(int row, int column) ;
    ~OSGRect();

public:
    void setOffset(float offset_x, float offset_z);
    void getOffset(float& offset_x, float& offset_z);
    void getAddOffset(osg::Vec3f& point);

    void setCornerPoint(osg::Vec3f p1, osg::Vec3f p2, osg::Vec3f p3, osg::Vec3f p4)    ;
    void getCornerPoint(osg::Vec3f& p1, osg::Vec3f& p2, osg::Vec3f& p3, osg::Vec3f& p4);
private:
    float offset_x_;
    float offset_z_;

    int row_   ;
    int column_;

    osg::Vec3f p1_, p2_, p3_, p4_;
};

class OSGGrid
{
public:
    OSGGrid() ;
    ~OSGGrid();

public:
    void initGrid(osg::Vec3f left_bottom, osg::Vec3f right_top);
    void getJustPoint(osg::Vec3f& point)  ;

    void getCornerPoint(osg::Vec3f& point);

    void getGridText(std::vector<std::string>& str, std::vector<osg::Vec3f>& center);

    void getGridLines(std::vector<osg::Vec3f>& points);

    void setCurrentRowColumn(int row, int column);

    void setJustPointOffset(float x, float z)  ;
    void getJustPointOffset(float& x, float& z);

    void readGrid(int i, int j, int x, int y);
    void writeGrid();

private:
    std::vector<std::vector<OSGRect>> grid_;

    float m_fSpaceX ;
    float m_fSpaceZ ;

    int m_iNumX;
    int m_iNumZ;

    osg::Vec3f left_bottom_;
    osg::Vec3f right_top_  ;

    int row_   ;
    int column_;
};

#endif
